package com.ipt.frm.pw.listener;

import java.io.IOException;
import java.util.Properties;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * Application Lifecycle Listener implementation class MsgListener
 *
 */
public class MsgListener implements ServletContextListener {

	
	static Properties propertiesMsg;
	static final private String PATH_PROPERTIES_MSG = "/WEB-INF/config/messages.properties";
	ServletContext context;
    /**
     * Default constructor. 
     */
    public MsgListener() {
        // TODO Auto-generated constructor stub
    }

	/**
     * @see ServletContextListener#contextInitialized(ServletContextEvent)
     */
    @Override
	public void contextInitialized(ServletContextEvent contextEvent) {
    	context = contextEvent.getServletContext();
    	propertiesMsg = new Properties();
    	try{
    		propertiesMsg.load(context.getResourceAsStream(PATH_PROPERTIES_MSG));
    		context.setAttribute("propiedad", propertiesMsg);
    	}catch(IOException e){
    		e.printStackTrace();
    	}
    }

	/**
     * @see ServletContextListener#contextDestroyed(ServletContextEvent)
     */
    @Override
	public void contextDestroyed(ServletContextEvent contextEvent) {
    	propertiesMsg = null;
    }
	
}
